import org.junit.Test;

import java.sql.Time;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by andy on 2016/11/2.
 */
public class TestTimmer {
    /***
     * ��ʱ��
     * S
     */
    static  int count=0;
    @Test
    public  void testTimmer(){
    /*        new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    System.out.println("Bombing----------");
                }
            },10000,3000); //10000,3000  每隔 3 秒炸一次
        while (true){
            System.out.println("当前秒" + new Date().getSeconds());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }*/

    // 先隔三秒砸一次  在隔6秒炸  定时器里面还有定时器
        class  MytimerTask extends  TimerTask{

        @Override
        public void run() {
            count=(count+1)%2;
            System.out.println("Bombing"+count);
            new Timer().schedule(new MytimerTask(),2000+2000*count);
        }

    }
        new Timer().schedule(new MytimerTask(),2000);
        while (true){
            System.out.println("当前秒" + new Date().getSeconds());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    //周一到周五发邮件晚上3:00  QuartZ    周六 不发

}

